package org.zjx.strategy.impl;

import org.zjx.action.Action;
import org.zjx.action.basic.DelayAction;
import org.zjx.action.login.*;
import org.zjx.action.service.AccountAction;
import org.zjx.core.IWindow;
import org.zjx.core.impl.LoginWindow;
import org.zjx.manager.WindowManager;
import org.zjx.state.AccountState;
import org.zjx.strategy.IStrategy;

public class LoginStrategy implements IStrategy {
    @Override
    public Action analyze(IWindow window) {

        if (window.getState().getState(AccountState.class) == null) {
            return new AccountAction(window);
        }

        if (LoginHomeAction.validate(window)) {
            return new LoginHomeAction(window);
        }
        if (LoginToggleAction.validate(window)) {
            return new LoginToggleAction(window);
        }
        if (LoginAccountAction.validate(window)) {
            return new LoginAccountAction(window);
        }
        if (LoginServerAction.validate(window)) {
            return new LoginServerAction(window);
        }
        if (LoginRoleAction.validate(window)) {
            return new LoginRoleAction(window);
        }
        if (LoginCreateAction.validate(window)) {
            return new LoginCreateAction(window);
        }

        String title = window.getTitle();
        if (title.contains("[")) {
            WindowManager.getInstance().convertToGameWindow((LoginWindow) window);
        }

        return new DelayAction(window,3000);
    }

    @Override
    public String getName() {
        return "登录策略";
    }

    @Override
    public int getPriority() {
        return 1;
    }

    @Override
    public boolean isApplicable(IWindow window) {
        return window instanceof LoginWindow;
    }
}
